//
//  MainTableViewCell.m
//  YiBaoStore
//
//  Created by 毛云河 on 2018/10/4.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "MainTableViewCell.h"

@implementation MainTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setMainCell];
    }
    return self;
}

- (void)setMainCell
{
    self.topTitleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.topTitleLabel];
    self.topTitleLabel.textAlignment = 0;
    self.topTitleLabel.font = FontWithSize(14);
    self.topTitleLabel.textColor = BlackTextColor;
    self.topTitleLabel.numberOfLines = 0;
    
    self.zanIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zan_main"]];
    [self.contentView addSubview:self.zanIcon];
    
    self.recommendLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.recommendLabel];
    self.recommendLabel.textAlignment = 0;
    self.recommendLabel.font = FontWithSize(12);
    self.recommendLabel.textColor = RGBACOLOR(153, 153, 153, 1);
    self.recommendLabel.numberOfLines = 0;
    
    self.costLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.costLabel];
    self.costLabel.font = FontWithSize(12);
    self.costLabel.textColor = RGBACOLOR(194, 194, 194, 1);
    self.costLabel.textAlignment = 2;
    
    self.priceBgView = [[UIView alloc] init];
    [self.contentView addSubview:self.priceBgView];
    self.priceBgView.backgroundColor = GrayTextColor;
    
//    self.leftImageIcon = [[UIImageView alloc]init];
//    [self.priceBgView addSubview:self.leftImageIcon];
    
    self.priceLabel = [[UILabel alloc] init];
    [self.priceBgView addSubview:self.priceLabel];
    self.priceLabel.textColor = BlackTextColor;
    self.priceLabel.font = FontWithSize(12);
    
    self.earningsLabel = [[UILabel alloc] init];
    [self.priceBgView addSubview:self.earningsLabel];
    self.earningsLabel.textColor = BlackTextColor;
    self.earningsLabel.font = FontWithSize(12);
    self.earningsLabel.textAlignment = 2;
    
    self.leftImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.leftImage];
    self.leftImage.contentMode = UIViewContentModeScaleAspectFill;
    self.leftImage.clipsToBounds = YES;
    
    self.rightTopImgae = [[UIImageView alloc]init];
    [self.contentView addSubview:self.rightTopImgae];
    self.rightTopImgae.contentMode = UIViewContentModeScaleAspectFill;
    self.rightTopImgae.clipsToBounds = YES;
    
//    self.rightDownImage = [[UIImageView alloc]init];
//    [self.contentView addSubview:self.rightDownImage];
//    self.rightDownImage.contentMode = UIViewContentModeScaleAspectFill;
//    self.rightDownImage.clipsToBounds = YES;
    
//    self.isShark = [[UILabel alloc]init];
//    [self.contentView addSubview:self.isShark];
//    self.isShark.textColor = BlackTextColor;
//    self.isShark.font = FontWithSize(12);
    
    self.shanrkBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:self.shanrkBtn];
    [self.shanrkBtn setTitle:@"分享" forState:UIControlStateNormal];
    [self.shanrkBtn setTitleColor:BlackTextColor forState:UIControlStateNormal];
    self.shanrkBtn.titleLabel.font = FontWithSize(12);
    self.shanrkBtn.backgroundColor = BtnBgColor;
    self.shanrkBtn.layer.cornerRadius = 15;
    self.shanrkBtn.layer.masksToBounds = YES;
    
//    self.lineView = [UIView new];
//    [self.contentView addSubview:self.lineView];
////    self.lineView.backgroundColor = GrayTextColor;
//    self.lineView.backgroundColor = [UIColor redColor];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.topTitleLabel.frame = CGRectMake(15, 20, self.width-30, 40);
    self.zanIcon.frame = CGRectMake(16, self.topTitleLabel.bottom+21, 10, 9);
    self.recommendLabel.frame = CGRectMake(42, self.topTitleLabel.bottom+8, SCREENWIDTH-42-21, 36);
    self.costLabel.frame = CGRectMake(SCREENWIDTH-25-200, self.recommendLabel.bottom+3, 200, 12);
    self.priceBgView.frame = CGRectMake(15, self.costLabel.bottom+10, self.topTitleLabel.width, 34);
//    self.leftImageIcon.frame = CGRectMake(10, 9, 16, 16);
    self.priceLabel.frame = CGRectMake(10, 11, 150, 12);
    self.earningsLabel.frame = CGRectMake(self.priceBgView.width-150-10, 11, 150, 12);
    
    CGFloat imageWidth = (SCREENWIDTH-34)/2;
    self.leftImage.frame = CGRectMake(15, self.priceBgView.bottom+10, imageWidth, 225);
    
    self.rightTopImgae.frame = CGRectMake(self.leftImage.right+4, self.leftImage.top, imageWidth, 225);
//    self.rightDownImage.frame = CGRectMake(self.rightTopImgae.left, self.rightTopImgae.bottom+2, imageWidth, imageWidth-1);
    
//    self.isShark.frame = CGRectMake(10, self.leftImage.bottom+29, 36, 12);
    self.shanrkBtn.frame = CGRectMake(self.width-70-15, self.leftImage.bottom+20, 70, 30);
//    self.lineView.frame = CGRectMake(0, self.shanrkBtn.bottom+29, SCREENWIDTH, 1);
}

- (void)setCellModel:(MainModel *)model
{
    self.topTitleLabel.text = [NSString stringWithFormat:@"%@",model.title];
    if (NOEmptyStr(model.describe_good))
    {
        self.recommendLabel.text = [NSString stringWithFormat:@"%@",model.describe_good];
        self.zanIcon.hidden = NO;
    }
    else {
        self.zanIcon.hidden = YES;
    }
    
    CGFloat shopCostPrice = [model.shopCostPrice floatValue];
    self.costLabel.text =[NSString stringWithFormat:@"成本价：￥%0.2f",shopCostPrice];
    CGFloat price = [model.price floatValue];
    self.priceLabel.text = [NSString stringWithFormat:@"店主销售价：￥%0.2f",price];
    CGFloat earnings = [model.price floatValue] - [model.shopCostPrice floatValue];
    self.earningsLabel.text = [NSString stringWithFormat:@"预计收益：￥%0.2f",earnings];
    
    self.leftImage.hidden = YES;
    self.rightTopImgae.hidden = YES;
    
    NSArray *imageArray = model.imageUrlList;
    for (int i = 0; i < model.imageUrlList.count; i++) {
        switch (i) {
            case 0:
            {
                self.leftImage.hidden = NO;
                [self.leftImage sd_setImageWithURL:[NSURL URLWithString:imageArray[i]] placeholderImage:[UIImage imageNamed:@"zhanwei400"]];
            }
                break;
                
            case 1:
            {
                self.rightTopImgae.hidden = NO;
                [self.rightTopImgae sd_setImageWithURL:[NSURL URLWithString:imageArray[i]] placeholderImage:[UIImage imageNamed:@"zhanwei400"]];
            }
                break;
                
            default:
                break;
        }
    }
    
    //    self.leftImageIcon.image = [UIImage imageNamed:@"24h"];
//    [self.rightDownImage sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"zhanwei100"]];
    
//    if ([model.shareStatus boolValue])
//    {
//        self.isShark.text = @"已分享";
//    }
//    else {
//        self.isShark.text = @"未分享";
//    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
